home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / pctchnqs / 1992 / number2 / wpro.c < prev   
Text File  |  1992-04-27  |  2KB  |  56 lines

  1. // WRITEPRO.C
  2.  
  3. #include <stdio.h>
  4. #include <dos.h>
  5. #include <stdlib.h>
  6.  
  7. #define RETURN_OK               0
  8. #define RETURN_WRITE_PROTECT    1
  9. #define RETURN_OTHER            2
  10.  
  11. char far buffer[10000];
  12. char far *pbuf = buffer;
  13.  
  14. void main(void);
  15.  
  16. void main(void)
  17. {
  18.     union REGS      inregs, outregs;
  19.     struct SREGS    segregs;
  20.     int             retries = 0;
  21.     int             rc = RETURN_OK;
  22.  
  23.     // Read logical sector 1
  24.     inregs.h.ah = 0x00;             // Just clear it out
  25.     inregs.h.al = 0x00;             // Disk drive A:
  26.     inregs.x.cx = 0x01;             // Number of sectors to read
  27.     inregs.x.dx = 0x01;             // Logical sector 1 (FAT)
  28.     inregs.x.bx = FP_OFF(pbuf);     // Offset of buffer
  29.     segregs.ds  = FP_SEG(pbuf);     // Segment address of buffer
  30.     int86x(0x25, &inregs, &outregs, &segregs);
  31.  
  32.     // If the carry flag is set, then there was an error
  33.     if (outregs.x.cflag) {
  34.     rc = RETURN_OTHER;
  35.     } else {
  36.     // Write logical sector 1
  37.     inregs.h.ah = 0x00;           // Just clear it out
  38.     inregs.h.al = 0x00;           // Disk drive A:
  39.     inregs.x.cx = 0x01;           // Number of sectors to write
  40.     inregs.x.dx = 0x01;           // Logical sector 1 (FAT)
  41.     inregs.x.bx = FP_OFF(pbuf);   // Offset of buffer
  42.     segregs.ds  = FP_SEG(pbuf);   // Segment address of buffer
  43.     int86x(0x26, &inregs, &outregs, &segregs);
  44.  
  45.     // If the carry flag is set, then there was an error
  46.     if (outregs.x.cflag) {
  47.         // If ah = 3 then there was a write protect error
  48.         if (outregs.h.ah == 3) {
  49.         rc = RETURN_WRITE_PROTECT;
  50.         } else {
  51.         rc = RETURN_OTHER;
  52.         }
  53.     }
  54.     }
  55.     exit(rc);
  56. }